package com.zhledu.course.string;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;

public class InsertIntoDataBase {
  public static void main(String[] args) throws Exception {
    String[] major = {"电子商务技术", "移动应用技术开发", "大数据技术与应用", "数字媒体艺术", "广告艺术设计", "会计", "计算机技术与应用", "房地产评估", "物业管理", "临床医学", "口腔医学", "兽医", "土木工程", "软件工程", "会计电算化", "凝聚态物理", "数学", "化学", "英语", "葡萄酒发酵技术", "法律", "汉语言文学"};

    Class.forName("com.mysql.jdbc.Driver");
    Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.1.105:3306/school?useSSL=false", "root", "zhli2008");

    int year = new Date().getYear() + 1900;
    StringBuffer sql = null;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    int n = 0;
    for (int i = 1; i <= 100000; i++) {
      sql = new StringBuffer();
      sql.append("insert into t_student VALUES (");
      sql.append("0, ");
      if (i % 1000 == 0) {
        n++;
        System.out.println(n);
      }
      sql.append(" '" + (2020000000 + n * 1000 + i % 1000) + "', ");
      sql.append(" '" + GenerateChineseName.getChineseName(i % 2 == 0) + "', ");
      String idNo = GenerateChineseName.getIdNo(i % 2 == 0);
      sql.append((year - Integer.parseInt(idNo.substring(6, 10))) + ", ");
      sql.append(" '" + (i % 2 == 0 ? "女" : "男") + "', ");
      sql.append(" '" + idNo.substring(6, 10) + "-" + idNo.substring(10, 12) + "-" + idNo.substring(12, 14) + "', ");
      sql.append(" '" + idNo + "', ");
      sql.append(" '" + GenerateChineseName.getNation(i % 2 == 0) + "', ");
      sql.append(" '" + GenerateChineseName.getPhone() + "', ");
      sql.append(" '" + major[GenerateChineseName.getNum(0, major.length - 1)] + "', ");
      sql.append(" '" + GenerateChineseName.getEmail() + "', ");
      sql.append(" '" + NativePlace.getNativePlace(Integer.parseInt(idNo.substring(0, 6))) + GenerateChineseName.getRoad() + "', ");
      sql.append(" '" + GenerateChineseName.getUserNameOrPassword() + "', ");
      sql.append(" '" + GenerateChineseName.getUserNameOrPassword() + "', ");
      sql.append(" '" + sdf.format(new Date()) + "', ");
      sql.append(" '" + sdf.format(new Date()) + "', ");
      sql.append(" '" + 0 + "')");
      Statement stmt = connection.createStatement();
      stmt.execute(sql.toString());
    }
    connection.close();
    System.out.println("执行完毕");

  }
}
